home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
stdlib1.exe
/
lha
/
SER1.ASM
< prev
next >
Wrap
Assembly Source File
|
1990-08-12
|
18KB
|
788 lines
stdlib segment para public 'slcode'
assume cs:stdlib
;
;
; Routines to handle COM1 data transmission.
;
; COM1 refers to HARDWARE COM1 port which is located beginning at port
; address 3f8h and causes INT 0Ch.
;
;
; Released to the public domain.
; Created by Randall Hyde.
; Date: 8/11/90
;
;
; Useful equates:
;
BIOSvars = 40h
Com1Adrs = 0
Com2Adrs = 2
;
BufSize = 256 ;# of bytes in buffer.
;
;
; Serial port equates:
;
Com1Port = 3F8h
Com1IER = 3F9h
Com1IIR = 3FAh
Com1LCR = 3FBh
Com1MCR = 3FCh
Com1LSR = 3FDh
Com1MSR = 3FEh
;
;
; Register assignments:
;
; Interupt enable register (IER):
;
; If one:
; bit 0- Enables received data available interrupt.
; bit 1- Enables transmitter holding register empty interrupt.
; bit 2- Enables receiver line status interrupt.
; bit 3- Enables the modem status interrupt.
; bits 4-7- Always set to zero.
;
; Interrupt ID Register (IIR):
;
; bit 0- No interrupt is pending (interrupt pending if zero).
; bits 1,2- Binary value denoting source of interrupt:
; 00-Modem status
; 01-Transmitter Hold Register Empty
; 10-Received Data Available
; 11-Receiver line status
; bits 3-7 Always zero.
;
;
; Line Control Register (LCR):
;
; bits 0,1- Word length (00=5, 01=6, 10=7, 11=8 bits).
; bit 2- Stop bits (0=1, 1=2 stop bits [1-1/2 if 5 data bits]).
; bit 3- Parity enabled if one.
; bit 4- 0 for odd parity, 1 for even parity (assuming bit 3 = 1).
; bit 5- 1 for stuck parity.
; bit 6- 1=force break.
; bit 7- 1=Divisor latch access bit. 0=rcv/xmit access bit.
;
; Modem Control Register (MCR):
;
; bit 0- Data Terminal Ready (DTR)
; bit 1- Request to send (RTS)
; bit 2- OUT 1
; bit 3- OUT 2
; bit 4- Loop back control.
; bits 5-7- Always zero.
;
; Line Status Register (LSR):
;
; bit 0- Data Ready
; bit 1- Overrun error
; bit 2- Parity error
; bit 3- Framing error
; bit 4- Break Interrupt
; bit 5- Transmitter holding register is empty.
; bit 6- Transmit shift register is empty.
; bit 7- Always zero.
;
; Modem Status Register (MSR):
;
; bit 0- Delta CTS
; bit 1- Delta DSR
; bit 2- Trailing edge ring indicator
; bit 3- Delta carrier detect
; bit 4- Clear to send
; bit 5- Data Set Ready
; bit 6- Ring indicator
; bit 7- Data carrier detect
;
;
; sl_Com1Baud: Set the COM1 port baud rate
; AX = baud rate (110, 150, 300, 600, 1200, 2400, 4800, 9600, 19200)
;
public sl_Com1Baud
sl_Com1Baud proc far
push ax
push dx
cmp ax, 9600
ja Set19200
je Set9600
cmp ax, 2400
ja Set4800
je Set2400
cmp ax, 600
ja Set1200
je Set600
cmp ax, 150
ja Set300
je Set150
mov ax, 1047 ;Default to 110 baud
jmp short SetPort
;
Set150: mov ax, 768
jmp short SetPort
;
Set300: mov ax, 384
jmp short SetPort
;
Set600: mov ax, 192
jmp short SetPort
;
Set1200: mov ax, 96
jmp short SetPort
;
Set2400: mov ax, 48
jmp short SetPort
;
Set4800: mov ax, 24
jmp short SetPort
;
Set9600: mov ax, 12
jmp short SetPort
;
Set19200: mov ax, 6
SetPort: mov dx, ax ;Save baud value.
call far ptr sl_GetLCRCom1
push ax ;Save old divisor bit value.
or al, 80h ;Set divisor select bit.
call far ptr sl_SetLCRCom1
mov ax, dx ;Get baud rate divisor value.
mov dx, Com1Port
out dx, al
inc dx
mov al, ah
out dx, al
mov dx, Com1LCR
pop ax
call far ptr sl_SetLCRCom1 ;Restore divisor bit value.
pop dx
pop ax
ret
sl_Com1Baud endp
;
;
; sl_Com1Stop:
; Set the number of stop bits.
;
; AL=1 for one stop bit, 2 for two stop bits.
;
public sl_com1Stop
sl_com1Stop proc far
push ax
push dx
dec ax
shl ax, 1 ;position into bit #2
shl ax, 1
mov ah, al
mov dx, Com1LCR
in al, dx
and al, 11111011b ;Mask out Stop Bits bit
or al, ah ;Mask in new # of stop bits.
out dx, al
pop dx
pop ax
ret
sl_com1Stop endp
;
;
; sl_com1size: Sets word size on the com1 port.
; AX = 5, 6, 7, or 8 which is the number of bits to set.
;
public sl_com1size
sl_com1size proc far
push ax
push dx
sub al, 5
cmp al, 3
jbe Okay
mov al, 3 ;Default to eight bits.
Okay: mov ah, al
mov dx, com1LCR
in al, dx
and al, 11111100b ;Mask out old word size
or al, ah ;Mask in new word size
out dx, al
pop dx
pop ax
ret
sl_com1size endp
;
;
; sl_com1parity: Turns parity on/off, selects even/odd parity, or stuck parity.
; ax contains the following:
;
; bit 0- 1 to enable parity, 0 to disable.
; bit 1- 0 for odd parity, 1 for even (only valid if bit 0 is 1).
; bit 2- Stuck parity bit. If 1 and bit 0 is 1, then the parity bit
; is always set to the inverse of bit 1.
;
public sl_com1parity
sl_com1parity proc far
push ax
push dx
;
shl ax, 1
shl ax, 1
shl ax, 1
and ax, 00111000b ;Mask out other data.
mov ah, al
mov dx, com1LCR
in al, dx
and al, 11000111b
or al, ah
out dx, al
pop dx
pop ax
ret
sl_com1parity endp
;
;
;****************************************************************************
;
; Polled I/O:
;
;
; sl_ReadCom1- Reads a character from COM1 and returns that character in
; the AL register. Synchronous call, meaning it will not
; return until a character is available.
;
public sl_ReadCom1
sl_ReadCom1 proc far
push dx
call far ptr sl_GetLCRCom1
push ax ;Save divisor latch access bit.
and al, 7fh ;Select normal port.
call far ptr sl_SetLCRCom1
mov dx, com1LSR
WaitForChar: call far ptr sl_GetLSRCom1
test al, 1 ;Data Available?
jz WaitForChar
mov dx, com1Port
in al, dx
mov dl, al ;Save character
pop ax ;Restore divisor access bit.
call far ptr sl_SetLCRCom1
mov al, dl ;Restore output character.
pop dx
ret
sl_ReadCom1 endp
;
;
;
; sl_WriteCom1- Writes the character in AL to the com1 port.
;
public sl_WriteCom1
sl_WriteCom1 proc far
push dx
push ax
mov dl, al ;Save character to output
call far ptr sl_GetLCRCom1
push ax ;Save divisor latch access bit.
and al, 7fh ;Select normal port.
call far ptr sl_SetLCRCom1
WaitForXmtr: call far ptr sl_GetLSRCom1
test al, 00100000b ;Xmtr buffer empty?
jz WaitForXmtr
mov al, dl ;Get output character.
mov dx, Com1Port
out dx, al
pop ax ;Restore divisor access bit.
call far ptr sl_SetLCRCom1
pop ax
pop dx
ret
sl_WriteCom1 endp
;
;
;
; sl_TstInpCom1-Returns AL=0 if a character is not available at the com1 port.
; Returns AL=1 if a character is available.
;
public sl_TstInpCom1
sl_TstInpCom1 proc far
push dx
mov dx, com1LSR
in al, dx
and al, 1
pop dx
ret
sl_TstInpCom1 endp
;
;
; sl_TstOutCom1-Returns AL=1 when it's okay to send another character to
; the transmitter. Returns zero if the transmitter is full.
;
public sl_TstOutCom1
sl_TstOutCom1 proc far
push dx
mov dx, com1LSR
in al, dx
test al, 00100000b
mov al, 0
jz toc1
inc ax
toc1: pop dx
ret
sl_TstOutCom1 endp
;
;
; sl_GetLSRCom1-Returns the LSR in al:
;
; AL:
; bit 0- Data Ready
; bit 1- Overrun error
; bit 2- Parity error
; bit 3- Framing error
; bit 4- Break interrupt
; bit 5- Xmtr holding register is empty.
; bit 6- Xmtr shift register is empty.
; bit 7- Always zero.
;
public sl_GetLSRCom1
sl_GetLSRCom1 proc far
push dx
mov dx, com1LSR
in al, dx
pop dx
ret
sl_GetLSRCom1 endp
;
;
; sl_GetMSRCom1-Returns the modem status register in AL
;
; AL:
; bit 0- Delta clear to send
; bit 1- Delta data set ready
; bit 2- Trailing edge ring indicator
; bit 3- Delta data carrier detect
; bit 4- Clear to send (CTS)
; bit 5- Data set ready (DSR)
; bit 6- Ring indicator (RI)
; bit 7- Data carrier detect (DCD)
;
public sl_GetMSRCom1
sl_GetMSRCom1 proc far
push dx
mov dx, com1MSR
in al, dx
pop dx
ret
sl_GetMSRCom1 endp
;
;
; sl_SetMCRCom1-Writes the data in AL to the modem control register.
; sl_GetMCRCom1-Reads the data from the modem control register into AL.
;
; AL:
; bit 0- Data terminal ready (DTR)
; bit 1- Request to send (RTS)
; bit 2- Out